//商品分类全局组件的小仓库
import {defineStore} from "pinia";
import {reqC1,reqC2,reqC3} from '@/api/product/attr/index.ts'
import type {CategoryResponseData} from '@/api/product/attr/type.ts'
import type {CategoryState} from '@/store/types/types.ts'

const useCategoryStore = defineStore('Category',{
    state:():CategoryState=>{
        return {
            //存储一级分类的数据
            c1Arr:[],
            //存储一级分类的ID
            c1Id:'',
            c2Arr:[],
            c2Id:'',
            c3Arr:[],
            c3Id:'',
        }
    },
    actions:{
        async getC1(){
           const res:CategoryResponseData= await reqC1()
            if(res.code==200){
                this.c1Arr=res.data
            }
        },
        async getC2(){
            const res:CategoryResponseData= await reqC2(this.c1Id)
            // console.log(res)
            if(res.code==200){
                this.c2Arr=res.data
            }
        },
        async getC3(){
            const res:CategoryResponseData= await reqC3(this.c1Id)
            // console.log(res)
            if(res.code==200){
                this.c3Arr=res.data
            }
        },
    },
    getters:{

    }
})

export default useCategoryStore